<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>class Legacy::TJPlurker - TJPlurker API Documentation</title>

<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../index.html">Home</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/tjplurker/legacy.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    <nav id="sections-section" class="section">
  <h3 class="section-header">Sections</h3>
  <ul class="link-list">
    
      <li><a href="#5Buntitled-5D"></a></li>
    
      <li><a href="#Offical+API+wrapping">Offical API wrapping</a></li>
    
      <li><a href="#TJPlurker+provided">TJPlurker provided</a></li>
    
  </ul>
</nav>

    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link">Object
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-c-new">::new</a>
    
    <li><a href="#method-i-add_all_as_friends">#add_all_as_friends</a>
    
    <li><a href="#method-i-become_fan">#become_fan</a>
    
    <li><a href="#method-i-comet_channel">#comet_channel</a>
    
    <li><a href="#method-i-get_friends_by_offset">#get_friends_by_offset</a>
    
    <li><a href="#method-i-get_plurks">#get_plurks</a>
    
    <li><a href="#method-i-get_public_profile">#get_public_profile</a>
    
    <li><a href="#method-i-get_user_channel">#get_user_channel</a>
    
    <li><a href="#method-i-login">#login</a>
    
    <li><a href="#method-i-plurk_add">#plurk_add</a>
    
    <li><a href="#method-i-response_add">#response_add</a>
    
    <li><a href="#method-i-tjp_get_friends">#tjp_get_friends</a>
    
    <li><a href="#method-i-tjp_super_become_fan">#tjp_super_become_fan</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="../GETSTART.html">GETSTART</a>
  
    <li class="file"><a href="../MAKEROBOT.html">MAKEROBOT</a>
  
    <li class="file"><a href="../README.html">README</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../Legacy.html">Legacy</a>
  
    <li><a href="../Legacy/TJPlurker.html">Legacy::TJPlurker</a>
  
    <li><a href="../Legacy/TJPlurker/NotificationData.html">Legacy::TJPlurker::NotificationData</a>
  
    <li><a href="../Legacy/TJPlurker/Robot.html">Legacy::TJPlurker::Robot</a>
  
    <li><a href="../Legacy/TJPlurker/Service.html">Legacy::TJPlurker::Service</a>
  
    <li><a href="../Legacy/TJPlurker/ThreadService.html">Legacy::TJPlurker::ThreadService</a>
  
    <li><a href="../TJP.html">TJP</a>
  
    <li><a href="../TJP/NotificationData.html">TJP::NotificationData</a>
  
    <li><a href="../TJP/Robot.html">TJP::Robot</a>
  
    <li><a href="../TJP/Service.html">TJP::Service</a>
  
    <li><a href="../TJP/TJPlurker.html">TJP::TJPlurker</a>
  
    <li><a href="../TJP/ThreadService.html">TJP::ThreadService</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class Legacy::TJPlurker</h1>

  <div id="description" class="description">
    
<h2 id="label-%E6%B3%A8%E6%84%8F">注意</h2>

<p>這是舊的函式庫，如果你想學習如何使用最新的TJPlurker，建議你應該參考 <a href="../GETSTART.html">此頁</a></p>

<p>如果你堅持享用舊版本，你應該在程式中如下引用以支援舊式的寫法：</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;tjplurker/legacy&quot;</span>
<span class="ruby-identifier">include</span> <span class="ruby-constant">Legacy</span>
</pre>

<p>而不是</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;tjplurker&quot;</span>
<span class="ruby-identifier">include</span> <span class="ruby-constant">TJP</span>
</pre>

<p>這是TJPlurker的核心類別，大部分的情況下此類別的方法都會回傳一個由Plurk Server產生的JSON物件。
所有的方法會在timeout發生的時候重新呼叫</p>

<p>It’s core class of <a href="TJPlurker.html">TJPlurker</a>. Note that every
methods in this class returns a JSON object which was converted from Plurk
server’s response. All mehtods will retry again when request timeout
occurs.</p>

  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    
    <!-- Attributes -->
    <section id="attribute-method-details" class="method-section section">
      <h3 class="section-header">Attributes</h3>

      
      <div id="attribute-i-user" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">user</span><span
            class="attribute-access-type">[R]</span>
        </div>

        <div class="method-description">
        
        <p>噗浪帳號 Plurk user ID.</p>
        
        </div>
      </div>
      
    </section><!-- attribute-method-details -->
    

    <!-- Methods -->
    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Class Methods</h3>

    
      <div id="method-c-new" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">new</span><span
            class="method-args">(api_key, user, passwd, auto_login=true)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <dl class="rdoc-list label-list"><dt>auto_login
<dd>
<p>是否在建構時自動登入 If <code>auto_login</code> sets <code>true</code>, it will
autologin while constructing.</p>
</dd></dl>
          

          
          <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 48</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span> <span class="ruby-identifier">api_key</span>, <span class="ruby-identifier">user</span>, <span class="ruby-identifier">passwd</span>, <span class="ruby-identifier">auto_login</span>=<span class="ruby-keyword">true</span>
    <span class="ruby-ivar">@user</span>, <span class="ruby-ivar">@passwd</span>, <span class="ruby-ivar">@api_key</span> = <span class="ruby-identifier">user</span>, <span class="ruby-identifier">passwd</span>, <span class="ruby-identifier">api_key</span>
    <span class="ruby-ivar">@cookie</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-ivar">@user_channel</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-ivar">@id_buffer</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">login</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">auto_login</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- new-source -->
          
        </div>

        

        
      </div><!-- new-method -->

    
    </section><!-- public-class-method-details -->
  
  </section><!-- 5Buntitled-5D -->

  
  
  <section id="Offical+API+wrapping" class="documentation-section">
    
    <div class="documentation-section-title">
      <h2 class="section-header">
        Offical API wrapping
      </h2>
      <span class="section-click-top">
        <a href="#top">&uarr; top</a>
      </span>
    </div>
    

    
    <div class="description">
      
<p>:section: Offical API wrapping 對Plurk官方API做包裹</p>

<p>Plurk API wrapping</p>

<p>登入</p>
<dl class="rdoc-list label-list"><dt>no_data
<dd>
<p>是否將登入成功後的訊息簡化成：</p>

<pre>{&quot;success_text&quot;: &quot;ok&quot;}</pre>

<p>否則將回傳使用者的詳細資料</p>

<p>If no_data sets true, the successful login message was simplified as
follow:</p>

<pre>{&quot;success_text&quot;: &quot;ok&quot;}</pre>

<p>Otherwise, more details of user’s profile were retured.</p>
</dd></dl>

    </div>
    

    

    

    <!-- Methods -->
    
     <section id="public-instance-Offical+API+wrapping-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-add_all_as_friends" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">add_all_as_friends</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>接受所有的好友邀請</p>

<p>Accept all friendship requests as friends. Successful return:</p>

<pre>{&quot;success_text&quot;: &quot;ok&quot;}</pre>
          

          
          <div class="method-source-code" id="add_all_as_friends-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 133</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">add_all_as_friends</span>
    <span class="ruby-identifier">method</span> = <span class="ruby-string">&quot;/API/Alerts/addAllAsFriends&quot;</span>
    <span class="ruby-identifier">attr</span> = {<span class="ruby-value">:api_key=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@api_key</span>}
    <span class="ruby-identifier">api</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">attr</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- add_all_as_friends-source -->
          
        </div>

        

        
      </div><!-- add_all_as_friends-method -->

    
      <div id="method-i-become_fan" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">become_fan</span><span
            class="method-args">(fan_id)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>成為粉絲</p>
<dl class="rdoc-list label-list"><dt>fan_id
<dd>
<p>你想追蹤的人的ID</p>

<p>The ID of the user you want to become fan of</p>
</dd></dl>
          

          
          <div class="method-source-code" id="become_fan-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 120</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">become_fan</span> <span class="ruby-identifier">fan_id</span>
    <span class="ruby-identifier">method</span> = <span class="ruby-string">&quot;/API/FriendsFans/becomeFan&quot;</span>
    <span class="ruby-identifier">attr</span> = {<span class="ruby-value">:api_key=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@api_key</span>, <span class="ruby-value">:fan_id=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">fan_id</span>}
    <span class="ruby-identifier">api</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">attr</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- become_fan-source -->
          
        </div>

        

        
      </div><!-- become_fan-method -->

    
      <div id="method-i-comet_channel" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">comet_channel</span><span
            class="method-args">() { |notification| ... }</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="comet_channel-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 185</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">comet_channel</span>
    <span class="ruby-comment">#Assign new channel if @user_channel is nil</span>
    <span class="ruby-ivar">@user_channel</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">get_user_channel</span>
    <span class="ruby-keyword">begin</span>
        <span class="ruby-identifier">res</span> = <span class="ruby-constant">Net</span><span class="ruby-operator">::</span><span class="ruby-constant">HTTP</span>.<span class="ruby-identifier">get_response</span>(<span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-ivar">@user_channel</span>[<span class="ruby-string">'comet_server'</span>]))
        <span class="ruby-identifier">json</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">res</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%rCometChannel\.scriptCallback\((.*)\);/</span>){<span class="ruby-operator">|</span><span class="ruby-identifier">match</span><span class="ruby-operator">|</span> <span class="ruby-node">$1</span>})
    <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
        <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-string">&quot;Request timeout, retry.&quot;</span>}
        <span class="ruby-keyword">retry</span>
    <span class="ruby-keyword">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ECONNRESET</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
        <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-string">&quot;Connection reset, retry.&quot;</span>}
        <span class="ruby-keyword">retry</span>
    <span class="ruby-keyword">rescue</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
        <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">fatal</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-string">&quot;Unknown error, skip.&quot;</span>}
        <span class="ruby-identifier">puts</span> <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">message</span>, <span class="ruby-identifier">ex</span>.<span class="ruby-identifier">backtrace</span>
        <span class="ruby-keyword">return</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-comment">#Update the offset</span>
    <span class="ruby-ivar">@user_channel</span>[<span class="ruby-string">'comet_server'</span>].<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">%r[\d]+$/</span>, <span class="ruby-identifier">json</span>[<span class="ruby-string">&quot;new_offset&quot;</span>].<span class="ruby-identifier">to_s</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">json</span>[<span class="ruby-string">'data'</span>]
        <span class="ruby-identifier">json</span>[<span class="ruby-string">'data'</span>].<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">member</span><span class="ruby-operator">|</span>
            <span class="ruby-identifier">notification</span> = <span class="ruby-constant">NotificationData</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">member</span>)
            <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">notification</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">==</span> <span class="ruby-ivar">@id_buffer</span>
            <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">info</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-node">&quot;Notification: #{notification.user_id}: \&quot;#{notification.content}\&quot;&quot;</span>}
            <span class="ruby-ivar">@id_buffer</span> = <span class="ruby-identifier">notification</span>.<span class="ruby-identifier">id</span>
            <span class="ruby-keyword">yield</span>(<span class="ruby-identifier">notification</span>)
        }
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">json</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- comet_channel-source -->
          
        </div>

        

        
      </div><!-- comet_channel-method -->

    
      <div id="method-i-get_friends_by_offset" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_friends_by_offset</span><span
            class="method-args">(user_id, limit=100, offset='0')</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>取得使用者的好友名單</p>

<p>Returns user_id’s friend list</p>
<dl class="rdoc-list label-list"><dt>limit
<dd>
<p>The max number of friends to be returned (default 10).</p>
</dd><dt>Successful return
<dd>
<p>好友名單陣列</p>

<p>Returns a list of JSON objects users, e.g.</p>

<pre>[{&quot;id&quot;: 3, &quot;nick_name&quot;: &quot;alvin&quot;, ...}, ...]</pre>
</dd><dt>warnning
<dd>
<p><code>limit</code>的最大值被官方設定為100，這個方法沒有很好用，建議你用<a
href="TJPlurker.html#method-i-tjp_get_friends">#tjp_get_friends</a>取代 This
maximum of <code>limit</code> is set 100 officially, this method is not
that useful. We suggest you use get_friend_list instead of
get_friends_by_offset.</p>
</dd></dl>
          

          
          <div class="method-source-code" id="get_friends_by_offset-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 152</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_friends_by_offset</span> <span class="ruby-identifier">user_id</span>, <span class="ruby-identifier">limit</span>=<span class="ruby-value">100</span>, <span class="ruby-identifier">offset</span>=<span class="ruby-string">'0'</span>
    <span class="ruby-identifier">method</span> = <span class="ruby-string">&quot;/API/FriendsFans/getFriendsByOffset&quot;</span>
    <span class="ruby-identifier">attr</span> = {<span class="ruby-value">:api_key=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@api_key</span>, <span class="ruby-value">:user_id=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">user_id</span>, <span class="ruby-value">:offset=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">offset</span>, <span class="ruby-value">:limit=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">limit</span>}
    <span class="ruby-identifier">api</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">attr</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- get_friends_by_offset-source -->
          
        </div>

        

        
      </div><!-- get_friends_by_offset-method -->

    
      <div id="method-i-get_plurks" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_plurks</span><span
            class="method-args">(limit=nil, offset=nil)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <dl class="rdoc-list note-list"><dt>Warning
<dd>
<p>It has bugs in offecial Plurk API.</p>
</dd></dl>
          

          
          <div class="method-source-code" id="get_plurks-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 173</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_plurks</span> <span class="ruby-identifier">limit</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">offset</span>=<span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">method</span> = <span class="ruby-string">&quot;/API/Polling/getPlurks&quot;</span>
    <span class="ruby-identifier">attr</span> = {<span class="ruby-value">:api_key=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@api_key</span>, <span class="ruby-value">:limit=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">limit</span>, <span class="ruby-value">:offset=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">offset</span>}
    <span class="ruby-identifier">api</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">attr</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- get_plurks-source -->
          
        </div>

        

        
      </div><!-- get_plurks-method -->

    
      <div id="method-i-get_public_profile" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_public_profile</span><span
            class="method-args">(user_id)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Fetches public information such as a user’s public plurks and basic
information. Fetches also if the current user is following the user, are
friends with or is a fan.</p>
<dl class="rdoc-list label-list"><dt>Successful return
<dd>
<p>Returns a JSON object with a lot of information that can be used to
construct a user’s public profile and timeline.</p>
</dd><dt>Error returns
<dd>
<p>HTTP 400 BAD REQUEST with {“error_text”: “Invalid user_id”} as body HTTP
400 BAD REQUEST with {“error_text”: “User not found”} as body</p>
</dd></dl>
          

          
          <div class="method-source-code" id="get_public_profile-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 166</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_public_profile</span> <span class="ruby-identifier">user_id</span>
    <span class="ruby-identifier">method</span> = <span class="ruby-string">&quot;/API/Profile/getPublicProfile&quot;</span>
    <span class="ruby-identifier">attr</span> = {<span class="ruby-value">:api_key=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@api_key</span>, <span class="ruby-value">:user_id=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">user_id</span>}
    <span class="ruby-identifier">api</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">attr</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- get_public_profile-source -->
          
        </div>

        

        
      </div><!-- get_public_profile-method -->

    
      <div id="method-i-get_user_channel" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">get_user_channel</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="get_user_channel-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 179</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">get_user_channel</span>
    <span class="ruby-identifier">method</span> = <span class="ruby-string">&quot;/API/Realtime/getUserChannel&quot;</span>
    <span class="ruby-identifier">attr</span> = {<span class="ruby-value">:api_key=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@api_key</span>}
    <span class="ruby-identifier">api</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">attr</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- get_user_channel-source -->
          
        </div>

        

        
      </div><!-- get_user_channel-method -->

    
      <div id="method-i-login" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">login</span><span
            class="method-args">(no_data=true)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="login-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 74</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">login</span> <span class="ruby-identifier">no_data</span>=<span class="ruby-keyword">true</span>
    <span class="ruby-identifier">method</span> = <span class="ruby-string">&quot;/API/Users/login&quot;</span>
    <span class="ruby-identifier">attr</span> = {<span class="ruby-value">:username=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@user</span>, <span class="ruby-value">:password=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@passwd</span>, <span class="ruby-value">:api_key=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@api_key</span>}
    <span class="ruby-identifier">attr</span>[<span class="ruby-value">:no_data</span>] = <span class="ruby-string">'1'</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">no_data</span>
    <span class="ruby-identifier">api</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">attr</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- login-source -->
          
        </div>

        

        
      </div><!-- login-method -->

    
      <div id="method-i-plurk_add" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">plurk_add</span><span
            class="method-args">(content, qualifier=':', limited_to=nil, no_comments=nil, lang='tr_ch')</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>發噗</p>

<p>範例：</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'tjplurker'</span>
<span class="ruby-identifier">tjp</span> = <span class="ruby-constant">TJPlurker</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;API Key&quot;</span>, <span class="ruby-string">&quot;帳號&quot;</span>, <span class="ruby-string">&quot;密碼&quot;</span>)
<span class="ruby-identifier">tjp</span>.<span class="ruby-identifier">plurk_add</span>(<span class="ruby-string">&quot;Hello TJPlurker&quot;</span>)
</pre>
          

          
          <div class="method-source-code" id="plurk_add-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 89</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">plurk_add</span> <span class="ruby-identifier">content</span>, <span class="ruby-identifier">qualifier</span>=<span class="ruby-string">':'</span>, <span class="ruby-identifier">limited_to</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">no_comments</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">lang</span>=<span class="ruby-string">'tr_ch'</span>
    <span class="ruby-identifier">method</span> = <span class="ruby-string">&quot;/API/Timeline/plurkAdd&quot;</span>
    <span class="ruby-identifier">attr</span> = {<span class="ruby-value">:api_key=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@api_key</span>, <span class="ruby-value">:content=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">content</span>, <span class="ruby-value">:qualifier=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">qualifier</span>,<span class="ruby-value">:limited_to=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">limited_to</span>, <span class="ruby-value">:no_comments=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">no_comments</span>, <span class="ruby-value">:lang=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">lang</span>}
    <span class="ruby-identifier">api</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">attr</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- plurk_add-source -->
          
        </div>

        

        
      </div><!-- plurk_add-method -->

    
      <div id="method-i-response_add" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">response_add</span><span
            class="method-args">(plurk_id, content, qualifier=':')</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>回噗</p>
<dl class="rdoc-list label-list"><dt>qualifier
<dd>
<p>可以是如下的字串：</p>

<p>Can be the following string:</p>

<pre>loves, likes, shares, gives, hates, wants, has, will,
asks, wishes, was, feels, thinks, says, is, :, freestyle, hopes, needs, wonders</pre>
</dd></dl>

<p>範例：</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'tjplurker'</span>
<span class="ruby-identifier">tjp</span> = <span class="ruby-constant">TJPlurker</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;API Key&quot;</span>, <span class="ruby-string">&quot;帳號&quot;</span>, <span class="ruby-string">&quot;密碼&quot;</span>)
<span class="ruby-identifier">json_obj</span> = <span class="ruby-identifier">tjp</span>.<span class="ruby-identifier">plurk_add</span>(<span class="ruby-string">&quot;Hello TJPlurker&quot;</span>)
<span class="ruby-identifier">tjp</span>.<span class="ruby-identifier">response_add</span>(<span class="ruby-identifier">json_obj</span>[<span class="ruby-string">&quot;plurk_id&quot;</span>], <span class="ruby-string">&quot;This is a reply.&quot;</span>, <span class="ruby-string">&quot;says&quot;</span>)
</pre>
          

          
          <div class="method-source-code" id="response_add-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 108</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">response_add</span> <span class="ruby-identifier">plurk_id</span>, <span class="ruby-identifier">content</span>, <span class="ruby-identifier">qualifier</span>=<span class="ruby-string">':'</span>
    <span class="ruby-identifier">method</span> = <span class="ruby-string">&quot;/API/Responses/responseAdd&quot;</span>
    <span class="ruby-identifier">attr</span> = {<span class="ruby-value">:api_key=</span><span class="ruby-operator">&gt;</span><span class="ruby-ivar">@api_key</span>, <span class="ruby-value">:plurk_id=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">plurk_id</span>, <span class="ruby-value">:content=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">content</span>, <span class="ruby-value">:qualifier=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">qualifier</span>}
    <span class="ruby-identifier">api</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">attr</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- response_add-source -->
          
        </div>

        

        
      </div><!-- response_add-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- Offical+API+wrapping -->

  
  
  <section id="TJPlurker+provided" class="documentation-section">
    
    <div class="documentation-section-title">
      <h2 class="section-header">
        TJPlurker provided
      </h2>
      <span class="section-click-top">
        <a href="#top">&uarr; top</a>
      </span>
    </div>
    

    
    <div class="description">
      
<p>:section: <a href="TJPlurker.html">TJPlurker</a> provided
由TJPlurker提供的工具，非官方有的方法</p>

<p>Those methos were all provided by TJPlukrer instead of plurk</p>

<p>這個方法游TJPlurker提供的非官方功能，改良自<a
href="TJPlurker.html#method-i-get_friends_by_offset">#get_friends_by_offset</a>，用於取得使用者所有的好友</p>

<p>This method is provided by <a href="TJPlurker.html">TJPlurker</a>. Improved
from <a
href="TJPlurker.html#method-i-get_friends_by_offset">#get_friends_by_offset</a>
for getting all friends of a user</p>
<dl class="rdoc-list label-list"><dt>max
<dd>
<p>取得多少好友，nil則無限制</p>

<p>The maximum number of your request. Set <code>nil</code> for unlimited.</p>
</dd><dt>return
<dd>
<p>陣列</p>

<p>An array contains friends</p>
</dd></dl>

<p>範例：</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'tjplurker'</span>
<span class="ruby-identifier">tjp</span> = <span class="ruby-constant">TJPlurker</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;API Key&quot;</span>, <span class="ruby-string">&quot;帳號&quot;</span>, <span class="ruby-string">&quot;密碼&quot;</span>)
<span class="ruby-identifier">friend_list</span> = <span class="ruby-identifier">tjp</span>.<span class="ruby-identifier">tjp_get_friends</span>(<span class="ruby-string">&quot;5874158&quot;</span>)
<span class="ruby-identifier">friend_list</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">friend</span><span class="ruby-operator">|</span> <span class="ruby-identifier">puts</span> <span class="ruby-identifier">friend</span>[<span class="ruby-string">&quot;uid&quot;</span>]}
</pre>

    </div>
    

    

    

    <!-- Methods -->
    
     <section id="public-instance-TJPlurker+provided-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-tjp_get_friends" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">tjp_get_friends</span><span
            class="method-args">(user_id, max=nil)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="tjp_get_friends-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 239</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">tjp_get_friends</span> <span class="ruby-identifier">user_id</span>, <span class="ruby-identifier">max</span>=<span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">list</span> = []
    <span class="ruby-identifier">offset</span> = <span class="ruby-value">0</span>;
    <span class="ruby-identifier">loop</span>{
        <span class="ruby-identifier">set</span> = <span class="ruby-identifier">get_friends_by_offset</span>(<span class="ruby-identifier">user_id</span>, <span class="ruby-value">100</span>, <span class="ruby-identifier">offset</span>)
        <span class="ruby-identifier">size</span> = <span class="ruby-identifier">set</span>.<span class="ruby-identifier">size</span>
        <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
        <span class="ruby-identifier">list</span> <span class="ruby-operator">|=</span> <span class="ruby-identifier">set</span>
        <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">max</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">list</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">max</span>
        <span class="ruby-identifier">offset</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">size</span>
    }
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">list</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- tjp_get_friends-source -->
          
        </div>

        

        
      </div><!-- tjp_get_friends-method -->

    
      <div id="method-i-tjp_super_become_fan" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">tjp_super_become_fan</span><span
            class="method-args">(fan_id, level=1)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>用於追蹤大量使用者的河道</p>
<dl class="rdoc-list label-list"><dt>level
<dd>
<p>深度，如等於1會追蹤使用者的所有好友，等於2則會追蹤使用者所有的好友以及好友的好友</p>
</dd></dl>
          

          
          <div class="method-source-code" id="tjp_super_become_fan-source">
            <pre><span class="ruby-comment"># File lib/tjplurker/legacy.rb, line 257</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">tjp_super_become_fan</span> <span class="ruby-identifier">fan_id</span>, <span class="ruby-identifier">level</span>=<span class="ruby-value">1</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">level</span><span class="ruby-operator">&lt;=</span><span class="ruby-value">0</span>
    <span class="ruby-identifier">become_fan</span>(<span class="ruby-identifier">fan_id</span>)
    <span class="ruby-identifier">list</span> = []
    <span class="ruby-identifier">offset</span> = <span class="ruby-value">0</span>;
    <span class="ruby-identifier">loop</span>{
        <span class="ruby-identifier">set</span> = <span class="ruby-identifier">get_friends_by_offset</span>(<span class="ruby-identifier">fan_id</span>, <span class="ruby-value">100</span>, <span class="ruby-identifier">offset</span>)
        <span class="ruby-identifier">size</span> = <span class="ruby-identifier">set</span>.<span class="ruby-identifier">size</span>
        <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
        <span class="ruby-identifier">tg</span> = <span class="ruby-constant">ThreadGroup</span>.<span class="ruby-identifier">new</span>
        <span class="ruby-identifier">set</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
            <span class="ruby-identifier">tg</span>.<span class="ruby-identifier">add</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span>{
                <span class="ruby-identifier">wait_sec</span> = <span class="ruby-value">1</span>
                <span class="ruby-keyword">until</span> <span class="ruby-identifier">become_fan</span>(<span class="ruby-identifier">i</span>[<span class="ruby-string">&quot;uid&quot;</span>]).<span class="ruby-identifier">key?</span>(<span class="ruby-string">&quot;success_text&quot;</span>)
                    <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">info</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-node">&quot;Trying to become #{i[&quot;uid&quot;]}'s fan in #{wait_sec} seconds&quot;</span>}
                    <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">wait_sec</span>)
                    <span class="ruby-identifier">wait_sec</span> <span class="ruby-operator">*=</span> <span class="ruby-value">2</span>
                <span class="ruby-keyword">end</span>
                <span class="ruby-identifier">$tjpLog</span>.<span class="ruby-identifier">info</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>){<span class="ruby-node">&quot;Become #{i[&quot;uid&quot;]}'s fan successfully&quot;</span>}
            }
        }
        <span class="ruby-identifier">tg</span>.<span class="ruby-identifier">list</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">join</span> }
        <span class="ruby-identifier">list</span> <span class="ruby-operator">|=</span> <span class="ruby-identifier">set</span>
        <span class="ruby-identifier">offset</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">size</span>
    }
    <span class="ruby-identifier">list</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">super_become_fan</span>(<span class="ruby-identifier">i</span>[<span class="ruby-string">&quot;uid&quot;</span>], <span class="ruby-identifier">level</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>)
    }
<span class="ruby-keyword">end</span></pre>
          </div><!-- tjp_super_become_fan-source -->
          
        </div>

        

        
      </div><!-- tjp_super_become_fan-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- TJPlurker+provided -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

